package com.jcu.itot;


import java.io.File;

import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.graphics.PixelFormat;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.VideoView;

public class MainActivity extends Activity {
GridView gridView;
MediaPlayer mp;
static final String[] iTot = new String[] { "Books","Videos"};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.grid);
		
		 gridView = (GridView) findViewById(R.id.gridView1);
		 gridView.setAdapter(new ImageAdapter(this, iTot));
		

		gridView.setOnItemClickListener(new OnItemClickListener() {
		
			@Override
			public void onItemClick(AdapterView<?> parent, View v, int position,
					long id) 
			{
				
				if(position==0)
				{
					bookview();
					/*Intent intent = new Intent(MainActivity.this,Books.class);
					startActivity(intent);
					Log.e("pos0",""+position);*/
					
				
				}
				if(position==1)
				{
					//video();
					Intent intent = new Intent(MainActivity.this, PlayVideoResFolder.class);
					startActivity(intent);
				}
				
			}
		});
			
			
		
			
		}
	public void bookview() 
	{
		//File pdfFile = new File("res/raw/java.pdf");
		//File pdfFile = new File("android.resource://com.jcu.itot/raw/java");
		//Log.e("pdffile",""+pdfFile);
		try {
			startActivity(new Intent(Intent.ACTION_VIEW,
	                Uri.parse(FileProvider.CONTENT_URI
	                    + "java.pdf")));}
		catch(ActivityNotFoundException e)
	    {
	        Toast.makeText(this, "No Application Available to view PDF",     Toast.LENGTH_SHORT).show();
	    }
		
	}
	
	


			/* (non-Javadoc)
			 * @see android.app.Activity#onBackPressed()
			 */
		
			public void onBackPressed() {
				final AlertDialog.Builder builder=new AlertDialog.Builder(this);
				//builder.setTitle("Alert Dialog");
				builder.setMessage("Are You Sure to Exit?");
				builder.setIcon(android.R.drawable.ic_dialog_alert);

				builder.setPositiveButton("OK", new OnClickListener() {
				public void onClick(DialogInterface dialog, int which) 
				{
					// to kill(close background process) the application
					android.os.Process.killProcess(android.os.Process.myPid());
					finish();
					return;
				}
				});

				builder.setNegativeButton("Cancel", new OnClickListener() {
				public void onClick(DialogInterface dialog, int which) 
				{
			
				
				}
				});

				builder.show();
				
				
			}
	
	
	
	}

